package acm.pta5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class T2_1 {
    public static void main(String[] args) throws IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        TreeSet<Node> resSet=new TreeSet<>((o1, o2) -> {
            if (o1.count== o2.count){
                return o1.total- o2.total;
            }
            return o2.count- o1.count;
        });
        int n = Integer.parseInt(in.readLine());
        String[] read=null;
        while (n-- > 0) {
            read=in.readLine().split(" ");
            Set<String> set = new HashSet<>();
            int k = Integer.parseInt(read[1]);
            for (int i = 2; i < read.length; i++) {
                set.add(read[i]);
            }
            if (resSet.size()<3){
                resSet.add(new Node(read[0],set.size(),k));
                continue;
            }
            if (resSet.last().count<set.size()){
                resSet.pollLast();
                resSet.add(new Node(read[0], set.size(),k));
            }
        }
        LinkedList<String> link=new LinkedList<>();
        Iterator<Node> it = resSet.iterator();
        for (int i = 0; i < 2; i++) {
            if (it.hasNext()) {
                System.out.printf(it.next().name+" ");
            }else {
                System.out.printf(it.next().name+"- ");
            }
        }
        if (it.hasNext()) {
            System.out.printf(it.next().name);
        }else {
            System.out.printf(it.next().name+"-");
        }
    }
    static class Node{
        String name;
        int count;
        int total;

        public Node(String name, int count, int total) {
            this.name = name;
            this.count = count;
            this.total = total;
        }
    }
}
